#!/usr/bin/env python
#coding=utf8

from . import Connector
from app.common.exception import ServiceError

class SubmailConnector(Connector):

    def __init__(self, client_id, secret_key, domain, app):
        super(SubmailConnector, self).__init__(client_id, secret_key, domain)
        self.app = app

    def send_subemail(self, appid, to, project, signature, var = None):
        """
        发送短信
        """
        url = "%s/message/xsend.json" % self.domain
        data = {
            "appid" : appid,
            "to" : to,
            "project" : project,
            "signature" : signature
        }
        if var:
            data["vars"] = var

        headers = {}
        r = self.packed_request(url, "POST", "发送短信错误", json=data, headers=headers)
        ret = r.json()

        return ret
